package com.wpw.java7demo.base;

import org.junit.Test;

import java.math.BigDecimal;

public class NumTest {
	
	@Test
	public void test() {
		BigDecimal d = new BigDecimal("0.345");
		BigDecimal add = new BigDecimal("0.655");
		BigDecimal add2 = d.add(new BigDecimal("0.655"));
		System.out.println(add2);
		
		BigDecimal subtract = add2.subtract(new BigDecimal("0.3451"));
		System.out.println(subtract);
	}
	
	/**
	 * 比较大小
	 */
	@Test
	public void test1() {
		BigDecimal d = new BigDecimal("0.345");
		BigDecimal add = new BigDecimal("0.3450");
		int compareTo = d.compareTo(add);
		System.out.println(compareTo);
		System.out.println(d.equals(add));
	}
	
	@Test
	public void test2() {
		BigDecimal d = new BigDecimal("0.345");
		BigDecimal multiply = d.multiply(new BigDecimal(-1));
		System.out.println(multiply);
	}
	
	@Test
	public void test3() {
		Double d = new Double(1.11d);
		System.out.println(Math.abs(d));
		System.out.println(-Math.abs(d));
	}

	@Test
	public void test4() {
		Integer i = 0;
		Integer j = null;
		i = i + j;//将会出错
		//这是在master分支上加上去的
		System.out.println(i);
	}
}
